/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package escom.ipn.administrador;

import escom.ipn.modelo.delegate.adminCRPDelegate;
import escom.ipn.modelo.delegate.adminRadioDelegate;
import escom.ipn.modelo.dto.CRPClass;
import escom.ipn.modelo.dto.PoliciaClass;
import escom.ipn.modelo.dto.RadioClass;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author db2admin
 */
@WebServlet(name = "eliminarCRP", urlPatterns = {"/eliminarCRP"})
public class eliminarCRP extends HttpServlet {

    /** 
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        adminCRPDelegate del = new adminCRPDelegate();
        adminCRPDelegate del1 = new adminCRPDelegate();
        adminRadioDelegate delR = new adminRadioDelegate();
        CRPClass a = new CRPClass();
        RadioClass r = new RadioClass();
        List crp;
        //Pedir datos
        int id=Integer.parseInt(request.getParameter("id"));
        a.setId_carro_radio_patrulla(id);
     
        try {
            if(a!=null){
            crp=del1.loadSelect(a);
            a= (CRPClass) crp.get(0);
            r.setId(a.getRADIO_COMUNICACION_id_radio());
            r.setAsignado(0);
            delR.asignacion(r);
            del.borrarUsuario(a);
            String redirectURL = "Administrador/administrador.jsp#tabcrp";
            response.sendRedirect(redirectURL);
            }
        } catch (SQLException ex) {
           out.println( "Fracaso");
        }
        
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
